module.exports = function(grunt) {
        
    grunt.initConfig({

        pkg: grunt.file.readJSON('package.json'),

        clean: {
            dist: 'dist',
        },

        less: {
            core: {
                options: {
                    strictMath: true,
                    sourceMap: true,
                    outputSourceFiles: true,
                    sourceMapURL: '<%= pkg.name %>.css.map',
                    sourceMapFilename: 'dist/css/<%= pkg.name %>.css.map'
                },
                src: 'less/coopera.less',
                dest: 'dist/css/<%= pkg.name %>.css'
            },
            themes: {
                options: {
                    strictMath: true,
                    sourceMap: true,
                    outputSourceFiles: true,
                    sourceMapURL: '<%= pkg.name %>-green-theme.css.map',
                    sourceMapFilename: 'dist/css/<%= pkg.name %>-green-theme.css.map'
                },
                src: 'less/green-theme.less',
                dest: 'dist/css/<%= pkg.name %>-green-theme.css'
            }
        },

        autoprefixer: {
            options: {
                browsers: [
                    'Android 2.3',
                    'Android >= 4',
                    'Chrome >= 20',
                    'Firefox >= 24', // Firefox 24 is the latest ESR
                    'Explorer >= 8',
                    'iOS >= 6',
                    'Opera >= 12',
                    'Safari >= 6'
                ]
            },
            core: {
                options: {
                    map: true
                },
                src: 'dist/css/<%= pkg.name %>.css'
            },
            themes: {
                options: {
                    map: true
                },
                src: 'dist/css/<%= pkg.name %>-green-theme.css'
            }
        },

        csslint: {
            options: {
                csslintrc: 'less/.csslintrc'
            },
            dist: [
                'dist/css/<%= pkg.name %>.css',
                'dist/css/<%= pkg.name %>-green-theme.css'
            ]
        },

        cssmin: {
            options: {
                compatibility: 'ie8',
                keepSpecialComments: '*',
                noAdvanced: true
            },
            core: {
                src: 'dist/css/<%= pkg.name %>.css',
                dest: 'dist/css/<%= pkg.name %>.min.css'
            },
            themes: {
                src: 'dist/css/<%= pkg.name %>-green-theme.css',
                dest: 'dist/css/<%= pkg.name %>-green-theme.min.css'
            }
        },

        csscomb: {
            options: {
                config: 'less/.csscomb.json'
            },
            dist: {
                expand: true,
                cwd: 'dist/css/',
                src: ['*.css', '!*.min.css'],
                dest: 'dist/css/'
            }
        },

        copy: {
            faFont: {
                src: 'fonts/*',
                dest: 'dist/'
            },
            faCss: {
                filter: 'isFile',
                src: 'fonts/font-awesome.min.css',
                dest: 'dist/css/font-awesome.min.css'
            }
        },

        watch: {
            less: {
                files: ['less/**/*.less'], // which files to watch
                tasks: ['less']   
            }
        }
    });
        
    require('load-grunt-tasks')(grunt, { scope: 'devDependencies' });

    // CSS distribution task.
    grunt.registerTask('less-compile', ['less:core', 'less:themes']);
    grunt.registerTask('dist-css', ['less-compile', 'autoprefixer:core', 'csscomb', 'cssmin:core']);
    
    // Full distribution task.
    grunt.registerTask('dist', ['clean', 'dist-css', 'copy']);

    // Default task.
    grunt.registerTask('default', ['clean', 'copy']);
};